package diancan.CGLIB;

import org.apache.log4j.Logger;
import org.springframework.cglib.proxy.MethodProxy;
import net.sf.cglib.proxy.MethodInterceptor;

import java.lang.reflect.Method;

public class TakeawayCGLIBInterceptor implements MethodInterceptor {
    Logger logger = Logger.getLogger(TakeawayCGLIBInterceptor.class);



     private Object target;

    /**
     *
     *   被代理的目标对象  ,看传入的是那个真实 实体
     * @param target
     */
    public TakeawayCGLIBInterceptor(Object target) {
         this.target = target;
     }


    @Override
    public Object intercept(Object o, Method method, Object[] objects, net.sf.cglib.proxy.MethodProxy methodProxy) throws Throwable {
        Object o1 = methodProxy.invokeSuper(o, objects);

        before();

        after();
        return "下单成功！订单信息:"+o1+"";
    }
    public void before(){
        System.out.println("===== 前置准备 =====");
        System.out.println("下单完成！准备做菜中...");
        System.out.println("召唤骑手上门取餐！");
        logger.info("前置准备完成（做菜+召唤骑手）");
    }
    public void after(){
        System.out.println("===== 后置配送 =====");
        System.out.println("骑手已取餐，正在配送...");
        System.out.println("餐品送达！拍照留证发送给客户～");
        logger.info("订单配送完成");
    }
}
